#include <netfwd.h>
#include <json/json.h>

using namespace std;
 
int64_t getCurrentTime()
{
    struct timeval tval;
    gettimeofday(&tval, NULL);
    return (tval.tv_sec * 1000000LL + tval.tv_usec);
}
 
char * str = "abcdefghijklmnopqrstuvwxyz";
 
void test1()
{
    int doc_count = 40;
    int outer_field_count = 80;
 
    Json::Value common_info;
 
    int64_t start_time = getCurrentTime();
 
    for(size_t i=0; i<doc_count; ++i)
    {
        Json::Value auc_info;
        for( size_t j=0 ; j<outer_field_count; ++j )
        {
            auc_info.append(str);
        }
        common_info.append(auc_info);
    }
 
    int64_t end_time = getCurrentTime();
 
    cout << "append time: " << end_time - start_time << endl;
}
 
void test2()
{
    int doc_count = 40;
    int outer_field_count = 80;
 
    Json::Value common_info;
 
    int64_t start_time = getCurrentTime();
 
    Json::Value auc_info;
 
    for(size_t i=0; i<doc_count; ++i)
    {
        for( size_t j=0 ; j<outer_field_count; ++j )
        {
            auc_info[j] = str;
        }
        common_info.append(auc_info);
    }
 
    int64_t end_time = getCurrentTime();
 
    cout << "opt append time: " << end_time - start_time << endl;
}
 
void test3()
{
    int doc_count = 40;
    int outer_field_count = 80;
 
    Json::Value common_info;
 
    int64_t start_time = getCurrentTime();
 
    Json::Value auc_info;
 
    for(size_t i=0; i<doc_count; ++i)
    {
        for( size_t j=0 ; j<outer_field_count; ++j )
        {
            auc_info[j] = Json::StaticString(str);
        }
        common_info.append(auc_info);
    }
 
    int64_t end_time = getCurrentTime();
 
    cout << "StaticString time: " << end_time - start_time << endl;
}
 
int main(int argc, const char *argv[])
{
    test1();
    test2();
    test3();
 
    return 0;
}
